package com.aaa.rent.service.impl;

import com.aaa.entity.CarType;
import com.aaa.rent.dao.CarTypeDao;
import com.aaa.rent.service.CarTypeService;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wys
 * @version 1.0
 * @date 2023/3/2 9:58
 */@Service
public class CarTypeServiceImpl  implements CarTypeService {
     @Autowired
     private CarTypeDao carTypeDao;
    @Override
    public Result selectCarType(CarType carType,Integer currentPage,Integer pageSize) {

        List<CarType> types = carTypeDao.selectList(null);
        return new Result(200,"查询成功",types);
    }

    @Override
    public Result insertCarType(CarType carType) {
        int insert = carTypeDao.insert(carType);
        return new Result(200,"添加成功",insert);
    }

    @Override
    public Result deleteCarType(Integer id) {
        int i = carTypeDao.deleteById(id);
        return new Result(200,"删除成功",i);
    }

    @Override
    public Result update(CarType carType) {
        int i = carTypeDao.updateById(carType);
        return new Result(200,"更新成功",i);
    }

    @Override
    public Result selectAllCarType(Integer currentPage,Integer pageSize,String tname) {
        PageHelper.startPage(currentPage,pageSize);
        QueryWrapper<CarType> wrapper = new QueryWrapper<>();
        wrapper.like(tname!=null ,"tname",tname);
        List<CarType> carTypes = carTypeDao.selectList(wrapper);
        PageInfo<CarType> pageInfo = new PageInfo<>(carTypes);
        return new Result(2000,"成功",pageInfo);
    }
}
